<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>watch完整写法</title>
  <script src="../vue.js"></script>
</head>

<body>
  <!-- 
    完整写法:一个新的值,受到多个属性控制改变,需要用到完整写法
    比如说,一个苹果,受到颜色和大小两个属性变化
   -->
  <div id="app">
    <input v-model="obj.color" type="text" name="" id="" placeholder="请输入颜色">
    <input v-model="obj.size" type="text" name="" id="" placeholder="请输入大小">
    <p>{{content}}</p>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        content: '',
        obj: {
          color: '1',
          size: '2'
        }
      },
      methods: {

      },
      computed: {

      },
      watch: {
        obj: {
          // 深度监视
          deep: true,
          // 进入页面就执行
          immediate: true,
          // 执行函数
          handler(newValue, oldValue) {
            console.log(newValue, oldValue);
            this.content = newValue.color + newValue.size
          }
        }
      }
    })
  </script>
</body>

</html>